home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / tp_tsr.zip / TSRES.ASM
Assembly Source File  |  1987-04-28  |  7KB  |  297 lines

  1. ;*************************************************************
  2. ;**   Terminate-but-Stay-Resident                           **
  3. ;**   Original from the "Programmer's Journal"              **
  4. ;**   Modified by Alroger L. Gomes Jr.                      **
  5. ;**   Any comments/question send message for "Roger Gomes"  **
  6. ;**   on the PDSE BBS (408)735-7190. Have Fun!              **
  7. ;*************************************************************
  8. ; Insert you program on line # 157.
  9.  
  10. Delay_Count     Equ     36                      ;36 ticks=approx. 2 seconds
  11.  
  12. ;  Locations of BIOS Data needed by the resident program
  13.  
  14. Bios_Data       Segment at 40h
  15.         Org     17h
  16.         Kbd_Status      dw      ?
  17.         Org     6Ch
  18.         Low_Timer       dw      ?
  19. Bios_Data       EndS
  20.  
  21.  
  22. Code            Segment
  23.         Assume  Cs:Code, Ds:Code, Es:Nothing, Ss:Nothing
  24.         Org     100h
  25. Entry_Point:
  26.         Jmp     Install
  27.  
  28.         Hot_Keys        dw      01010B
  29.         This_Time       dw      ?
  30.         Trig_Time       dw      ?
  31.         Dos_Busy        Label   dword
  32.         Dos_Busy_Off    dw      ?
  33.         Dos_Busy_Seg    dw      ?
  34.         Criterr_Flag    db      ?
  35.  
  36. Already8    db    0
  37. MenuON      db      0
  38.  
  39.  
  40. ;*** Replacement for Int 24h - critical Dos Error ***
  41. Diverted_Int24:
  42.         Mov     Cs:Criterr_Flag,1
  43.         Xor     Al,Al
  44.         Iret
  45.  
  46.         Int_24_Vect     Label   dword
  47.         Int_24_Off      dw      ?
  48.         Int_24_Seg      dw      ?
  49.  
  50. ;***** ID CODE *****
  51. Res_ID1 dw      'Al'
  52. Res_ID2 dw      'ro'
  53. Res_ID3 dw      'ge'
  54. ;*******************
  55.  
  56. ;*** Replacement for Int 8 - Timer hardware Interrupt ***
  57. Diverted_Int8:
  58.         Pushf
  59.         Call_Int8       db      09Ah
  60.         Int_8_Vect      Label   dword
  61.         Int_8_Off       dw      ?
  62.         Int_8_Seg       dw      ?
  63.  
  64.         Cmp     Cs:MenuOn,0
  65.         Je      MenuNOT
  66.     Iret
  67. MenuNOT:
  68.     Mov    Cs:MenuOn,1
  69.         Push    Ds
  70.         Push    Bx
  71.         Lds     Bx,Cs:Dos_Busy
  72.         Cmp     Byte Ptr [Bx],0
  73.         Pop     Bx
  74.         Pop     Ds
  75.     Mov    Cs:MenuOn,0
  76.     Jz    Get_Bios_Data
  77. Dos_is_Busy:
  78.         Iret
  79.  
  80. ;*** Replacement for Int 28 - Generated by Dos, esp. during keyboard I/O ***
  81. Diverted_Int28:
  82.         Pushf
  83.         Call_Int28      db      09Ah
  84.         Int_28_Vec      Label   dword
  85.         Int_28_Off      dw      ?
  86.         Int_28_Seg      dw      ?
  87.     Cmp    Cs:MenuOn,0
  88.     Je    Get_Bios_Data
  89.     Iret    
  90.  
  91. Get_Bios_Data:
  92.     Mov    Cs:MenuOn,1
  93.         Sti
  94.         Push    Ds
  95.         Push    Ax
  96.         Mov     Ax,Bios_Data
  97.         Mov     Ds,Ax
  98.         Assume  Ds:Bios_Data
  99.         Mov     Ax,Low_Timer
  100.         Mov     Cs:This_time,Ax
  101.         Mov     Ax,Kbd_Status
  102.         Push    Cs
  103.         Pop     Ds
  104.         Assume  Ds:Code
  105. Chk_Keys:
  106.         And     Ax,Hot_Keys
  107.         Cmp     Ax,Hot_Keys
  108.         Jne     Back_to_Applic
  109. Chk_Timer:
  110.         Mov     Ax,This_Time
  111.         Cmp     Ax,Trig_Time
  112.         Jb      Time_is_Right
  113.         Sub     Ax,Trig_Time
  114.         Sub     Ax,Delay_Count
  115.         Jnc     Time_is_Right
  116.  
  117. Back_to_Applic:
  118.         Pop     Ax
  119.         Pop     Ds
  120.     Mov    Cs:MenuOn,0
  121.         Iret
  122.  
  123. Time_is_Right:
  124.         Mov     Ax,This_Time
  125.         Mov     Trig_Time,Ax
  126.         Pop     Ax
  127.         Pop     Ds
  128.  
  129. ;***************************************************************************
  130. ; This is the Start of the application-dependent resident code
  131.  
  132. Start_Program:
  133.     Mov    Cs:MenuOn,1
  134.         Push    Ax
  135.         Push    Bx
  136.         Push    Cx
  137.         Push    Dx
  138.         Push    Si
  139.         Push    Di
  140.         Push    Bp
  141.         Push    Ds
  142.         Push    Es
  143.  
  144.         Push    Cs
  145.         Pop     Ds
  146.  
  147.         Mov     Ax,3524h
  148.         Int     21h
  149.         Mov     Int_24_Off,Bx
  150.         Mov     Int_24_Seg,Es
  151.         Mov     Ax,2524h
  152.         Mov     Dx,Offset Diverted_Int24
  153.         Int     21h
  154.  
  155. ;****************************************************************************
  156.  
  157. ; Insert your program here.
  158.  
  159. ;****************************************************************************
  160.  
  161. Restore_Int24:
  162.         Lds     Dx,Int_24_Vect
  163.         Mov     Ax,2524h
  164.         Int     21h
  165.         Pop     Es
  166.         Pop     Ds
  167.         Pop     Bp
  168.         Pop     Di
  169.         Pop     Si
  170.         Pop     Dx
  171.         Pop     Cx
  172.         Pop     Bx
  173.         Pop     Ax
  174.         Mov     Cs:MenuOn,0
  175.     Mov    Cs:Already8,0
  176.         Iret
  177.  
  178. ;  This is the end off the applicant-dependent resident code
  179.  
  180.         End_of_Res      Label   word
  181.  
  182. ;***************************************************************************
  183. ; Installation
  184.  
  185. Install:
  186.     Mov    Ax,Cs
  187.     Mov    Ds,Ax
  188.     Mov    Es,Ax
  189.  
  190.     Mov    Ah,9
  191.     Mov    Dx,OffSet CopyRight
  192.     Int    21h
  193.  
  194. ; Make sure that it is at least Dos 2.00
  195.         Mov     Ah,30h
  196.         Int     21h
  197.         Or      Al,Al
  198.         Jnz     Chk_Vectors
  199.         Mov     Dx,Offset BadDos_Msg
  200.         Mov     Ah,9
  201.         Int     21h
  202.         Int     20h
  203.  
  204. ; See if resident code is already Installed in Memory
  205.  
  206. Chk_Vectors:
  207.     Mov    Ax,Cs
  208.     Mov    Ds,Ax
  209.     Mov    Es,Ax
  210.  
  211.         Mov     Ax,3508h
  212.         Int     21h
  213.         Cmp     Word Ptr [Es:Bx-6],'Al'
  214.         Jne     Not_Installed1
  215.         Cmp     Word Ptr [Es:Bx-4],'ro'
  216.         Jne     Not_Installed1
  217.         Cmp     Word Ptr [Es:Bx-2],'ge'
  218.         Jne     Not_Installed1
  219.  
  220.         Mov     Dx,Offset No_Install_Msg
  221.         Mov     Ah,9
  222.         Int     21h
  223.         Mov     Ax,4C01h
  224.         Int     21h
  225.  
  226. Not_Installed1:
  227.         Mov     Ax,3577h
  228.         Int     21h
  229.     Mov    Ax,Es
  230.         Cmp     Ax,'Al'
  231.         Jne     Not_Installed
  232.         Cmp     Bx,'ro'
  233.         Jne     Not_Installed
  234.  
  235.         Mov     Dx,Offset No_Install_Msg
  236.         Mov     Ah,9
  237.         Int     21h
  238.         Mov     Ax,4C01h
  239.         Int     21h
  240.  
  241. Not_Installed:
  242.     Mov    Ax,Cs
  243.     Mov    Ds,Ax
  244.     Mov    Es,Ax
  245.  
  246.         Push    Es
  247.     Mov    Ax,Cs
  248.     Mov    Ds,Ax
  249.     Mov    Es,Ax
  250.  
  251.         Mov     Ah,34h
  252.         Int     21h
  253.         Mov     Dos_Busy_Off,Bx
  254.         Mov     Dos_Busy_Seg,Es
  255.  
  256.         Mov     Ax,3508h
  257.         Int     21h
  258.         Mov     Int_8_Off,Bx
  259.         Mov     Int_8_Seg,Es
  260.     
  261.     Mov    Ax,Cs
  262.     Mov    Es,Ax
  263.     Mov    Ds,Ax
  264.  
  265.         Mov     Ax,2508h
  266.         Mov     Dx,Offset Diverted_Int8
  267.         Int     21h
  268.  
  269.     Mov    Ax,'Al'
  270.     Mov    Ds,Ax
  271.     Mov    Dx,'ro'
  272.     Mov    Ax,2577h
  273.     Int    21h
  274.     Mov    Ax,Cs
  275.     Mov    Ds,Ax
  276.  
  277.         Mov     Ax,3528h
  278.         Int     21h
  279.         Mov     Int_28_Off,Bx
  280.         Mov     Int_28_Seg,Es
  281.         Mov     Ax,2528h
  282.         Mov     Dx,Offset Diverted_Int28
  283.         Int     21h
  284.         Pop     Es
  285.  
  286. ; Terminate and stay resident
  287.     Mov    Dx,Offset Install
  288.     Int    27h
  289.  
  290. No_Install_Msg  db      'xxxx is already in memory!',10,13,10,13,'$'
  291. BadDos_Msg      db      'DOS 2.0 or greater needed!',10,13,10,13,'$'
  292. CopyRight    db      'xxxx by ?????? - yyyy        $'
  293.  
  294. Code    EndS
  295.         End     Entry_Point
  296.  
  297.